﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.ViewModel;
using System.ComponentModel;
using System.Collections.ObjectModel;
using Microsoft.Practices.Prism.Modularity;
using System.Windows.Media.Imaging;
using System.IO;
using PetroMentor.Service;
namespace HSE.Common
{
    public class ToolBarNaviInfo : NotificationObject
    {

        public ToolBarNaviInfo()
        {
            this.SubItems = new ObservableCollection<ToolBarNaviInfo>();
        }

        public void Init(T_CFG_MODULE info)
        {
            this.Id = info.ID;
            this.Name = info.ALIAS;
            this.Ref = info.XAP;
            if (info.INITTYPE == 0)
                this.InitializationMode = Microsoft.Practices.Prism.Modularity.InitializationMode.WhenAvailable;
            else
                this.InitializationMode = Microsoft.Practices.Prism.Modularity.InitializationMode.OnDemand;
            this.Icon = info.ICONPATH;
            this.ModuleName = info.NAME;
            this.ViewName = info.VIEWNAME;
            this.IsChecked = info.ISDEFAULT==0?false:true;
        }
        public string Id { get; set; }

        public string Name { get; set; }

        public string Icon { get; set; }

        /// <summary>
        /// 引用
        /// </summary>
        public string Ref { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        public string ModuleName { get; set; }

        /// <summary>
        /// 初始状态
        /// </summary>
        public InitializationMode InitializationMode { get; set; }

        public string ViewName { get; set; }

        private bool isLiked = false;
        public bool IsLiked
        {
            get { return this.isLiked; }
            set { 
                if (this.isLiked != value) {
                   this.isLiked = value;
                   this.RaisePropertyChanged("IsLiked");
                }
            }
        }

        private bool ischecked = false;
        public bool IsChecked
        {
            get { return this.ischecked; }
            set
            {
                if (this.ischecked != value)
                {
                    this.ischecked = value;
                    this.RaisePropertyChanged("IsChecked");
                }
            }
        }


        private double order = 0;
        public double Order
        {
            get { return this.order; }
            set { 
                if (this.order != value) { 
                    this.order = value;
                    this.RaisePropertyChanged("Order");
                }
            }
        }

        

        private ObservableCollection<ToolBarNaviInfo> _subItems;
        public ObservableCollection<ToolBarNaviInfo> SubItems
        {
            get
            {
                return this._subItems;
            }

            set
            {
                this._subItems = value;
                this.RaisePropertyChanged("SubItems");

            }
        }


        private Visibility _newVisibility;
        public Visibility NewVisibility
        {
            get
            {
                return this._newVisibility;
            }

            set
            {

                this._newVisibility = value;
                this.RaisePropertyChanged("NewVisibility");
            }

        }

        private int _newnum;
        public int Newnum
        {
            get
            {
                return this._newnum;
            }

            set
            {

                this._newnum = value;
                if (_newnum > 0)
                    this.NewVisibility = Visibility.Visible;
                else
                    this.NewVisibility = Visibility.Collapsed;
                this.RaisePropertyChanged("Newnum");
            }
        }

    }

    public class PhotoInfo : NotificationObject
    {
        public string _icon;
        public string Icon
        {
            get
            {
                return this._icon;
            }
            set
            {
                this._icon = value;
                this.RaisePropertyChanged("Icon");
            }
        }

        public byte[] _iconcontent;
        public byte[] IconContent
        {
            get
            {
                return this._iconcontent;
            }
            set
            {
                this._iconcontent = value;
                MemoryStream ms = Util.GetMemoryStream(this._iconcontent);
                BitmapImage bitimg = new BitmapImage();
                bitimg.SetSource(ms);
                this._iconBitmap = bitimg;
                this.RaisePropertyChanged("IconContent");
            }
        }

        /// <summary>
        /// 图标
        /// </summary>
        private BitmapImage _iconBitmap;
        public BitmapImage IconBitmap
        {
            get { return this._iconBitmap; }

            set
            {
                this._iconBitmap = value;
                this.RaisePropertyChanged("IconBitmap");
            }

        }

        private string _tipinfo;
        public string TipInfo
        {
            get
            {
                return this._tipinfo;
            }
            set
            {
                this._tipinfo = value;
                this.RaisePropertyChanged("TipInfo");
            }
        }
    }

    public class PictureAttachmentViewModel : NotificationObject
    {
        private string _title;
        public string Title
        {
            get { return this._title; }
            set
            {
                this._title = value;
                this.RaisePropertyChanged("Title");
            }
        }

        private ObservableCollection<PhotoInfo> _photos;
        public ObservableCollection<PhotoInfo> Photos
        {
            get { return this._photos; }
            set
            {
                this._photos = value;
                this.RaisePropertyChanged("Photos");
            }
        }
    }
}
